// JavaScript Document

(function($){  
var    
    numid=0,
    doll = window.jQuery.fn.doll
	     = window.$.fn.doll   
		 =
	function(jQ) {
		
		if(typeof jQ =="undefined"){
			//当不传参数时 this 指向doll对象
			this.operName="__doll";
			jQ=this;
		}else{
			//当传参时构建一个jQuery对象
			if(typeof jQ !=""){
				jQ=window.jQuery(jQ);
				this.operName="__jQuery";
			}
		}
	    return new doll.fn.init(jQ);
	};
	 	
    doll.fn = doll.prototype = {
	_doll:function(){
		 $._prof("#debug",this)
		 
	},
	operN:"empty",
	operateObj:{a:"a"},
	constructor: doll ,
	getOper:function(){
		this.operN=this;
		//$._prof("#debug",this)
	    return this.operateObj;	
	},
	getThis:function(){
		 alert(this.constructor);
		},
	init:function( jQ ){
		if(jQ!="undefined"){
		    this.operateObj=jQ
		}else{
		 
		// $._prof("#debug",this.operateObj)//这里的this指的是doll对象
		this.operateObj=this;
		}
		 
		return this
		
		},
	fx:function(){
	 
		// $._prof("#debug",this);
		alert('这是类库的一个实例化方法[fx]');
	},
	_html:function(json){
		 ////alert(0)
		 /// $._prof("#debug",this)//这里的this指的是doll对象
		  // window.doll.fn._html.apply(this,[]) al函数改变了this 的指向
		  //现在指向 jQ
		 ////alert(this)
		 this.css(json)
	    return doll();	
	} ,
	_bg:function(obj,json){
	  return $.doll()._html.apply(obj,[json]);	
	  
	},
	_new:function(json){
	  return $.doll()._html.apply(this.operateObj,[json]);	
	},
	getjQ:function(jQobj){
		return jQobj;
		}
	}; 

    doll.fn.init.prototype = doll.fn;

    doll.tool=function(){
        alert("插件的工具方法测试");	
    }
	
	doll.mkdiv =function(str){	
	    var div = document.createElement('div');
        div.innerHTML = str;
		div.style.border="#ccc solid 2px";
		div.style.marginBottom="20px";
		return div;	
    }
	doll.getThis=function(ar){
		  
		  alert(numid+"->\n"+ar.constructor+"\n{"+ar+"}\n");
	 numid++;
		
	}
	doll.inFullScreen=false;
	doll.fullscreen = function (divObj) {
		 
		if(typeof divObj=="undefined"){
			divObj=document.documentElement; 
		}
	    //$.doll._prof("#debug",divObj)
        if (divObj.requestFullscreen) {
			
            divObj.requestFullscreen();
        }
        else if (divObj.msRequestFullscreen) {
            divObj.msRequestFullscreen();
		}
        else if (divObj.mozRequestFullScreen) {
            divObj.mozRequestFullScreen();
        }
        else if (divObj.requestFullscreen 
		|| ('webkitRequestFullScreen' in document.documentElement) ) 
		{    try{
					 //支持谷歌
					 // 对 Chrome 特殊处理，
					 // 参数 Element.ALLOW_KEYBOARD_INPUT 使全屏状态中可以键盘输入。
					if ( window.navigator.userAgent.toUpperCase().indexOf( 'CHROME' ) >= 0 ) {
						$.doll.jBox("chrom浏览正在器全屏")
						 divObj.webkitRequestFullScreen( Element.ALLOW_KEYBOARD_INPUT );
						 
						//elem.webkitRequestFullScreen();
					}else{		
				
                        divObj.webkitRequestFullscreen();
					}
		     }catch(e){
				 //支持 safari5.1
				 divObj.webkitRequestFullScreen();
				 
			 }
        }
		else{		     		 
			alert("你的浏览器不支持全屏！");
		}
        //doll.inFullScreen = true;
        return;
      }
	  
	  
	  doll.exitFullscreen = function () {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        }
        else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        }
        else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        }
        else if (document.webkitCancelFullScreen) {
			
          document.webkitCancelFullScreen();
        }
        //doll.inFullScreen = false;
        return;
      }
	  
	  
	  
    doll.fn.fxn=function(n){
	    alert(n+":"+"fxn:doll的实例方法")	
	}
	
 

//第一种方法 扩展jQ的实例方法
	$.fn.foo2=function(){
		var i=0;
			for(p in this){
				i++;
				if(i>5){return;}
				alert(p);
				alert(this[p]);	
			}	
	}
	$.fn.toA=function(){
	  return [].slice.call( this );	
	}
	window.$.fn.getThis=
	window.jQuery.fn.getThis=function(){
		 alert(this.constructor);
		
	}
	
//第二种方法 扩展jQ的实例方法
$.fn.extend({ 
   fxfx:function(){alert("fxfx")},
   toArr: function(){
	  return [].slice.call( this );	
   },
   al:function(){
	   alert(this)
	   // $._prof("#debug",this)//这里的this指的是jQ对象
	   return window.doll.fn._html.apply(this,[])
	   },
   //_get()返回一个原生的js集合 与jQ的 get方法是一样的
    _get: function(num){
    return num == null ?

			// Return a 'clean' array
			this.toArray() :

			// Return just the object
			( num < 0 ? this[ this.length + num ] : this[ num ] );
    },
    _test: function(){
	   
	 var i=0;
			for(p in this){
				i++;
				if(i<2){
					
					alert(p);
					alert(this[p]);	
					x=this[p];
				}
			}	
	        var j=0;
			 
			for(p in x){
				j++;
				 if(j>1){return;}
			    alert(p);	
			}  
    },
	_prop:function(len,num){
		if( typeof len != "string" && typeof len != "number" ){
			try{
		
				for(  p in this ){
					$(num).append($.doll.mkdiv(
							p + ":<br>&nbsp;&nbsp;&nbsp;&nbsp;<pre>" +  
							(  len==-1 || len=="" ? this[p] : 
							   this[p]  ) +"</pre>"
						));
                  		 
		        }
		   }catch(e){alert(e)}
		   
		}else{
		    this._prop_(len,num);
		}
	},
	_prop_:function(len,num){		 
		num= typeof num == "undefined" ? 10 : num;		 
		len= typeof len == "undefined" ? 50: len;
		var i=0; 
		try{
		for(  p in this ){
			i++;
		    if( i < num || num==-1){
			this.append($.doll.mkdiv(
			    p + ":<br>&nbsp;&nbsp;&nbsp;&nbsp;<pre>" +  
				(  len==-1 || len=="" ? this[p] : 
				   this[p].toString().substr(0,len)  ) +"</pre>"
			));
			}		 
		}
		}catch(e){}
	    return this;	
	}
			

})

    window.doll= window._ = doll;
	

    //第一种方法扩展jQ的工具方法
    window.jQuery.doll=window.doll;
	  
	
    //第二种方法扩展jQ的工具方法
    $.extend({
		tool2:function(){
			alert("插件的工具方法测试2")
		},
		_prop:$.fn._prop ,
		
		_prof:function(id,obj){
		   obj= typeof obj == "undefined" ? window : obj;	
		   $._prop.apply(obj,[obj,id]);
		}
		
	});
	
	$.extend(doll,{
		tool2:function(){
			alert("插件的工具方法测试2")
		},
		_prop:$.fn._prop ,
		
		_prof:function(id,obj){
		   obj= typeof obj == "undefined" ? window : obj;	
		   $._prop.apply(obj,[obj,id]);
		}
		
	});
	
	$.extend(doll,{
		tool3:function(){
			alert("插件的工具方法测试3")
		}
		
	});
	
		
})(window.jQuery)


$.doll.fullscreenEnabled = 
    ( function() {
        var doc = document.documentElement;
        return ( 'requestFullscreen' in doc ) ||
               ( 'webkitRequestFullScreen' in doc ) ||
               // 对Firefox除了能力判断，还加上了属性判断
               ( 'mozRequestFullScreen' in doc && document.mozFullScreenEnabled ) ||
               false;
    } )();
	

$.doll.removeChild=function(father,childs){	
    if(typeof childs=="undefined"){
		childs=father;
		for(i=0;i<childs.length;i++){
		    childs[i].parentNode.removeChild( childs[i] )	
		}
	   return;	
	}
    for(i=0;i<childs.length;i++){
		try{ 	
	    father.removeChild( childs[i] );
		}catch(e){
		    //childs[i].parentNode.removeChild( childs[i] )	
		}
	}
}	

//相对文档
$.doll.getMousePagePos=function (event) {
	
	var e = event || window.event ||  arguments.callee.caller.arguments[0]/*支持火狐*/ ;
	var scrollX = document.documentElement.scrollLeft 
	              || document.body.scrollLeft;
	var scrollY = document.documentElement.scrollTop 
	              || document.body.scrollTop;
	  			  
	var x = e.pageX || e.clientX + scrollX;
	var y = e.pageY || e.clientY + scrollY;

	return [x,y];
}

//相对屏幕
$.doll.getMouseScreenPos=function (event) {             
    var e = event || window.event   ||  arguments.callee.caller.arguments[0];            
     return [e.screenX,e.screenY]   
} 

//相对相对浏览器窗口
$.doll.getMouseClientPos=function (event) {              
 var e = event || window.event  ||  arguments.callee.caller.arguments[0];              
 return [e.clientX,e.clientY]  
 } 

$.doll.trace=function(id,msgJSON,time){
	if(typeof time=="undefined"){time=7000;}
	if(typeof msgJSON=="undefined"){msgJSON={error:"错误未定义"};}
	  $.doll.removeChild( 
		      $(id+' div').get()
		    ) 
		    $.doll._prof( 
		      id , msgJSON
		    )
			$(id).css({display:"block"})
				window.setTimeout(function(){
				     $(id).hide(2000)
				},time
			)
			 	
}

$.doll.sec2date=function (sec){
	//转两个占位符表式 2变成02
	//to2placeholder
	 
	function to2 (n){
		return n<10 ?	0+""+n : n ;
	}		
	s=to2(sec%60)
	m=to2(
		 parseInt     (sec/60) % 60   
	);
	h=to2( parseInt (
		    ( sec/(60*60) ) % 60      
	));
	return  h!=0 ? h +":"+  m +":"+  s  :  m +":"+  s ;  
}

$.doll.getLocalTime=function (timestamp,chinese){
    if (!timestamp){
		var date=new Date()
        datetime = date.toLocaleString()+":"+date.getMilliseconds();
    }else{
        datetime = new Date(parseInt(timestamp)*1000).toLocaleString();
    }
    if (!chinese){
        return datetime.replace(/年|月/g, '-').replace(/日/g, '');
    }
    return datetime;
}

$.doll.getScreenWidth=function(){
    return window.screen.width;	
}

$.doll.getScreenHeight=function(){
    return window.screen.height;	
}
$.doll.listener=function(){
     window.onerror = function(errorMessage, scriptURL, lineNumber) {
     alert(errorMessage);
     alert(scriptURL);    
	 alert(lineNumber);
     }	
}
//$.doll.listener();
 
 
 
	
	
 

var temp=(function(window){
	var getRandomColor=function (){}
	 
	getRandomColor.a=new Array('red','green','yellow','blue' );
	getRandomColor.prototype={
		constructor:getRandomColor 	
	}
	getRandomColor.upcolor='';
	getRandomColor.ret='red';
	getRandomColor.getRColor=function(){	
	var k=Math.floor(Math.random()*getRandomColor.a.length);
	getRandomColor.ret=  getRandomColor.a[k];
	getRandomColor.a.splice(k,1);	  
	if(getRandomColor.a.length==0){
		getRandomColor.a= new Array('red','green','yellow','blue' );
	}	  
	getRandomColor.upcolor=getRandomColor.ret;
		  
	return getRandomColor.ret;
	}
	 
window.$.getRandomColor=getRandomColor;
})(window)
 var temp=1;

$.doll.jBox=function(content,title){
	 if (typeof title==='undefined'){
		 title=$.doll.getLocalTime()
	}
	if (typeof content==='undefined'){
		 content=$.doll.getScreenWidth()
	} 
		// $('#myNotice').click(function() {
		 new jBox('Notice', {
			attributes: {
			x: 'left',
			y: 'bottom'
		},
		position: {   
			x: 'center',
			y: 200
		},

			 title: 'T:'+title,
			content: content,
			width: Math.floor($.doll.getScreenWidth()*0.8) ,
			 opacity:0.2,
			animation: 'flip'/*zoomIn zoomOut pulse move slide flip tada*/
			,/*open: 'move:top',*/
			color:$.getRandomColor.getRColor()
			  
	 
		}).audio({url: 'audio/beep1', volume: 75}) 
		
		;
 
	//});	
			
}

$.doll.setTimeOut=function(fn,time ){
	if(typeof time ==="undefined"){time=10;}
	window.setTimeout(
		function(){fn()},time
	)	
}	
 
 
 $.doll.mklogodiv=function(){
    var _body=document.getElementsByTagName('body')[0];
	var div = document.createElement("div");
	var atr=document.createAttribute("mySttribute");
    atr.nodeValue="mySttribute value";
    div.setAttributeNode(atr); 
	div.id='logo';
	div.style.position = 'fixed'; 
	div.style.opacity='0.8';
	div.style.filter=' alpha(opacity=80)'
	div.style.zIndex='1000';
	div.style.right='50px';
	div.style.padding='5px';
	div.style.display = 'block';
	div.style.color = '#fff';
	//div.style.backgroundColor='#fff';
	div.innerHTML='<img src="../inc/logo.png" width="200" height="200">';
	_body.insertBefore(div,_body.childNodes[0]);
	$.doll.jBox('创建div id:logo')
}